<template>
    <div>
        <Row :gutter="10">
            <Col span="24">
            <Card class="slideList">
                <p slot="title" style="height: 32px">
                    <Icon type="ios-settings-strong"></Icon>
                    系统设置
                    <Button type="success" @click="saveSystemSetting">保存</Button>
                </p>
                <Tabs>
                    <TabPane label="基础设置" icon="android-settings">
                        <Form ref="systemSettingModel" :model="systemSettingModel" :rules="ruleValidate" :label-width="100" class="Form_kuang">
                            <FormItem label="分享词语配置" prop="shareTemplate">
                                <Input v-model="systemSettingModel.shareTemplate" placeholder="请输入描述" style="width:200px"/>
                            </FormItem>
                            <FormItem label="CDN">
                                <i-switch v-model="systemSettingModel.is_cdn" prop="is_cdn" size="large">
                                    <span slot="open">开启</span>
                                    <span slot="close">关闭</span>
                                </i-switch>
                            </FormItem>
                            <FormItem label="热门条件" prop="hot">
                                <Select v-model="systemSettingModel.hot" style="width:200px">
                                    <Option v-for="item in hotList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                                </Select>
                            </FormItem>
                        </Form>
                    </TabPane>
                    <TabPane label="广播设置" icon="settings">
                        <Form ref="systemSettingModel" :model="systemSettingModel" :rules="ruleValidate" :label-width="100" class="Form_kuang">
                            <FormItem label="直播间广告" prop="shareTemplate">
                                <Input v-model="systemSettingModel.liveNotice" placeholder="请输入描述" style="width:200px"/>
                            </FormItem>
                            <FormItem label="平台广告" prop="shareTemplate">
                                <Input v-model="systemSettingModel.platformNotice" placeholder="请输入描述" style="width:200px"/>
                            </FormItem>
                        </Form>
                    </TabPane>
                    <TabPane label="分享比例设置" icon="ios-pie">
                        <Form ref="systemSettingModel" :model="systemSettingModel" :rules="ruleValidate" :label-width="100" class="Form_kuang">
                            <FormItem label="一级比例">
                                <InputNumber :max="100" :min="0" v-model="systemSettingModel.levelone"></InputNumber>%
                            </FormItem>
                            <FormItem label="二级比例">
                                <InputNumber :max="100" :min="0" v-model="systemSettingModel.leveltwo"></InputNumber>%
                            </FormItem>
                            <FormItem label="三级比例">
                                <InputNumber :max="100" :min="0" v-model="systemSettingModel.levelthree"></InputNumber>%
                            </FormItem>
                        </Form>
                    </TabPane>
                </Tabs>
            </Card>
            </Col>
        </Row>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                selectURl:'/system/one',
                upURl:'/system/update',
                systemSettingModel:{},
                hotList:[
                    {
                        value: 1,
                        label: '观看人数'
                    },
                    {
                        value: 2,
                        label: '观看人数和人气'
                    }
                ],
                ruleValidate: {
                    tag: [
                        { required: true, message: '优惠信息不能为空', trigger: 'blur' },
                    ],
                    title: [
                        { required: true, message: '产品名称不能为空', trigger: 'blur' },
                    ]
                },
            }
        },
        created () {
            this.getData();
        },
        methods: {
            //初始化时获取数据
            getData () {
                let self = this;
                self.$axios.get(self.selectURl).then((res) => {
                    self.systemSettingModel = res.data.data;
                    self.systemSettingModel.levelone = parseInt(self.systemSettingModel.levelone*100);
                    self.systemSettingModel.leveltwo = parseInt(self.systemSettingModel.leveltwo*100);
                    self.systemSettingModel.levelthree = parseInt(self.systemSettingModel.levelthree*100);
                })
            },
            saveSystemSetting(){
                let self=this;
                self.systemSettingModel.levelone = self.systemSettingModel.levelone/100;
                self.systemSettingModel.leveltwo = self.systemSettingModel.leveltwo/100;
                self.systemSettingModel.levelthree = self.systemSettingModel.levelthree/100;
                self.$axios.post(self.upURl,self.systemSettingModel).then((res) => {
                    if (res.data.code==200){
                        self.$Message.success('恭喜您，保存成功');
                        self.getData();
                    }else {
                        self.$Message.error('抱歉，保存失败。请稍后重试!');
                        self.getData();
                    }
                })
            },

    }
    }
</script>
<style>
    .Form_kuang{
        height: 550px;
    }
</style>